<style scoped>
  .sellform >>> .weui-form-preview__hd .weui-form-preview__value {
    font-size: 1.2em;
    padding-right: 20px;
  }
  .sellform {
    background: #e3e3e3;
  }
  .page-infinite-wrapper {
    background: #e3e3e3;
  }
  .sellform >>> .weui-cells {
    margin-top: 0;
    background: #e3e3e3;
  }
  .sellform >>> .weui-loadmore__tips {
    background: #e3e3e3;;
  }
  .sellform >>> .weui-loadmore {
    margin-bottom: 0;
  }
  .weui-form-preview {
    margin: 5px;
    border-radius: 5px;
  }

  .rj-cell-child {
    display: inline-block;
    font-size: 0;
    padding: 5px 15px;
    text-align: left;
  }
  .rj-cell-child.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell-child.minpad{
    padding-right: 10px !important;
  }
  .rj-cell-child label {
    color: #333;
    font-size: 14px;
  }
  .rj-cell-child span {
    padding-left: 20px;
    font-size: 14px;
    color: #333;
  }
  .rj-cell-child .tip {
    font-size: 16px;
    color: #333;
  }
  .rj-cell-child i {
    font-size: 18px;
    font-style: normal;
    color: #333;
  }
  .rj-cell-child-tit {
    background: #eee;
    font-size: 14px;
    padding: 5px 15px;
    border-bottom: 1px solid #ddd;
  }
  .weui-form-preview__ft .weui-form-preview {
    background: #f5f5ef;
  }
  .weui-form-preview__ft {
    line-height: normal;
  }



  .weui_tab_bd {
    background: #eee;
  }
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui_navbar {
    white-space: nowrap;
    overflow: scroll;
    display: block !important;
    border-bottom: 1px solid #BCBAB6;
    font-size: 0;
    /*background: #fafafa;*/
  }
  .weui_navbar_item {
    font-size: 14px;
    display: inline-block;
    width: 20%;
    padding: 13px 0;
    background: #fff;
    position: relative;
    color: #888;
  }
  .weui_navbar_item.weui_bar_item_on {
    background-color: #f5f5f5;
    color: #00913a;
  }
  .weui_navbar:after {
    border-bottom: 0;
  }
  .weui_navbar_item:after {
    content: " ";
    position: absolute;
    right: 0;
    top: 0;
    width: 1px;
    height: 100%;
    border-right: 1px solid #cccccc;
    color: #cccccc;
    -webkit-transform-origin: 100% 0;
    transform-origin: 100% 0;
    -webkit-transform: scaleX(0.5);
    transform: scaleX(0.5);
    font-size: 10px;
  }
  .weui-panel__bd {
    text-align: left;
  }
  .hoverbar {
    background: #03A9F4;
    position: fixed;
    bottom: 100px;
    right: 20px;
    height: 50px;
    line-height: 50px;
    width: 50px;
    z-index: 100;
    font-size: 30px;
    border-radius: 50%;
    box-shadow: 0px 2px 3px rgba(100, 100, 100, 0.5);
    color: #fff;
  }
  .delsty {
    position: absolute;
    top: 2px;
    right: 0px;
    z-index: 1000;
  }
</style>
<template>
  <div class="sellform">
    <div class="hoverbar" v-show="salperms"  @click="addItem">+</div>
    <SearchBar @doSearch="doSearch" />
    <div class="weui_tab">
      <div class="weui_navbar order-tabhd">
        <a class="weui_navbar_item" v-for="(item, index) in tabTitles" :key="item.guid" :style="'width:' + tabWidth" :class="{ weui_bar_item_on: postParams.stat == item.stats }" href="javaScript:;" @click="switchStatus(item.stats)">{{item.name}}</a>

<!--        <a class="weui_navbar_item" :class="{ weui_bar_item_on: postParams.stat == '00' }" href="javaScript:;" @click="switchStatus('00')">待处理</a>-->
<!--        <a class="weui_navbar_item" :class="{ weui_bar_item_on: postParams.stat == 11 }" href="javaScript:;" @click="switchStatus(11)">审批中</a>-->
<!--        <a class="weui_navbar_item " :class="{ weui_bar_item_on: postParams.stat == 22 }" href="javaScript:;" @click="switchStatus(22)">生产加工</a>-->
<!--        <a class="weui_navbar_item " :class="{ weui_bar_item_on: postParams.stat == 33 }" href="javaScript:;" @click="switchStatus(33)">已出库</a>-->
<!--        <a class="weui_navbar_item " :class="{ weui_bar_item_on: postParams.stat == 44 }" href="javaScript:;" @click="switchStatus(44)">已到货</a>-->
<!--        <a class="weui_navbar_item " :class="{ weui_bar_item_on: postParams.stat == 55 }" href="javaScript:;" @click="switchStatus(55)">待结算</a>-->
<!--        <a class="weui_navbar_item " :class="{ weui_bar_item_on: postParams.stat == 66 }" href="javaScript:;" @click="switchStatus(66)">已回款</a>-->
<!--        <a class="weui_navbar_item " :class="{ weui_bar_item_on: postParams.stat == 77 }" href="javaScript:;" @click="switchStatus(77)">已作废</a>-->
      </div>
      <div class="weui_tab_bd" style="background-color: #fff">
        <div class="page-infinite-wrapper" ref="wrapper" :style="{ height: wrapperHeight + 'px' }" >
            <mescroll-vue ref="mescroll" id="wrapper" :down="mescrollDown" :up="mescrollUp" @init="mescrollInit">
              <div class="weui-form-preview" v-for="(item, index) in data" :key="item.guid" :ref="item.guid">
<!--                <div class="delsty" @click="delScrap(item.guid)" v-show="userid == item.operatorid && item.status <= 6"><i class="weui-icon-cancel"></i></div>-->
                <div class="weui-form-preview__hd" @click="viewItem(item.guid)">
                <label class="weui-form-preview__label">订单编号</label>
                <em class="weui-form-preview__value">{{item.sellcode}}</em>
              </div>
              <div class="weui-form-preview__bd">
                <div class="weui-form-preview__item">
                  <label class="weui-form-preview__label">申请人</label>
                  <span class="weui-form-preview__value">{{item.applyname}}</span>
                </div>
                <div class="weui-form-preview__item" v-show="saladmperms || userid == item.operatorid">
                  <label class="weui-form-preview__label">客户</label>
                  <span class="weui-form-preview__value">{{item.customername}}</span>
                </div>
                <div class="weui-form-preview__item" v-show="saladmperms || userid == item.operatorid">
                  <label class="weui-form-preview__label">所在地区</label>
                  <span class="weui-form-preview__value">{{item.arriprovince + item.arricity + item.arridistrict}}</span>
                </div>
                <div class="weui-form-preview__item">
                  <label class="weui-form-preview__label">重量</label>
                  <span class="weui-form-preview__value">{{item.orderweight}} 吨</span>
                </div>
                <div class="weui-form-preview__item">
                  <label class="weui-form-preview__label">销售形式</label>
                  <span class="weui-form-preview__value">{{item.saletypename}}</span>
                </div>
                <div class="weui-form-preview__item">
                  <label class="weui-form-preview__label">发货工厂</label>
                  <span class="weui-form-preview__value">{{item.storeroomname}}</span>
                </div>
                <div class="weui-form-preview__item">
                  <label class="weui-form-preview__label">状态</label>
                  <span class="weui-form-preview__value">{{item.statusname}}</span>
                </div>
                <div class="weui-form-preview__item">
                  <label class="weui-form-preview__label">备注</label>
                  <span class="weui-form-preview__value" style="color: #000;">{{item.remarks}}</span>
                </div>
                <div class="weui-form-preview__item">
                  <label class="weui-form-preview__label">创建时间</label>
                  <span class="weui-form-preview__value">{{item.createtime}}</span>
                </div>
              </div>
              <div class="weui-form-preview__ft olist">
                <!--                <div class="weui-panel__hd"></div>-->
                <div class="weui-panel__bd">
                  <div class="weui-form-preview" v-for="(product, index) in item.items" :key="product.guid">
                    <div class="rj-cell-child-tit">产品明细 {{index+1}}</div>
                    <div class="rj-cell-child max">
                      <label>品&nbsp;&nbsp;&nbsp;种：</label><span>{{product.productname}}</span> <span>{{product.spname}} </span>
                    </div>
                    <div class="rj-cell-child">
                      <label>重&nbsp;&nbsp;&nbsp;量：</label><span>{{product.weight}} 吨</span>
                    </div>
                    <div class="rj-cell-child" v-show="saladmperms || edpriceperms || setlperms || backperms || userid == item.operatorid">
                      <label>单&nbsp;&nbsp;&nbsp;价：</label><span>{{product.price}} 元</span><span></span>
                    </div>
                    <div class="rj-cell-child">
                      <label>备&nbsp;&nbsp;&nbsp;注：</label><span>{{product.remark}}</span>
                    </div>
                  </div>
                </div>
              </div>
              <div class="weui-form-preview__ft" style="line-height: 50px;">
<!--                <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="item.operatorid == userid && item.status == 8"  @click="toOrderSure(item.guid)">到货确认 </a>-->
<!--                <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="item.operatorid == userid &&  item.status == 1" @click="sellCheck(item.guid)" >提交</a>-->
<!--                <template v-for="(node, index) in item.nodes">-->
                      <a class="weui-form-preview__btn weui-form-preview__btn_primary" v-for="(node, index) in item.nodes" :key="node.guid" href="javascript:" v-if="postParams.stat == '00' && filterPerm(node.permission, item.storermguid, item.depguid, item.operatorid)" @click="doAct(node.operate, item.guid, node.guid, node.name, node.annex)" >{{node.name}}</a>
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" :href="'/vuecode/#/sellform/sendCar?openid=' + openid + '&guid=' + item.guid" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 1 && permission.srguid == item.storermguid && permission.permission == 9 && (item.status == 4 || item.status == 5 || item.status == 6 || item.status == 7)" >派车</a>-->
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 1 && permission.srguid == item.storermguid && permission.permission == 12 && (item.status == 4 || item.status == 5 || item.status == 6 || item.status == 7 || item.status == 8 || item.status == 9)" @click="doAct('ChangePrice', item.guid)" >调价</a>-->
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 4 && permission.permission == 11 && (item.status == 3 || item.status == 4 || item.status == 5 || item.status == 6)" @click="doAct('SellDispatch', item.guid)">调度</a>-->
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 2 && permission.departid == item.depguid && permission.permission == 2 && (item.status == 2 || item.status == 3 || item.status == 4 || item.status == 5 || item.status == 6)"  @click="doAct('CustomerEdit', item.guid)">客户变更</a>-->
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 1 && permission.srguid == item.storermguid && permission.permission == 4 && item.status == 6" @click="doAct('OutStoreRoom', item.guid)">出库</a>-->
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 1 && permission.srguid == item.storermguid && permission.permission == 9 && (item.status == 8 || item.status == 9)" @click="doAct('EditLine', item.guid)">线路调整</a>-->
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 1 && permission.srguid == item.storermguid && permission.permission == 9 && item.status == 9" @click="doAct('SellFinalSure', item.guid)">结算确认</a>-->
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 1 && permission.srguid == item.storermguid && permission.permission == 6 && item.status == 4"  @click="sellAssign(item.guid)" >出库派单</a>-->
<!--                  <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" v-if="permission.permss.functiontype.indexOf(1) >= 0 && permission.permss.scopetype == 1 && permission.srguid == item.storermguid && permission.permission == 9 && (item.status == 9 || item.status == 10 || item.status == 11)" @click="doAct('ConfirmFare', item.guid)" >运费结算</a>-->
<!--                </template>-->
              </div>
              </div>
            </mescroll-vue>
        </div>

      </div>
    </div>

  </div>
</template>

<script>
  import MescrollVue from 'mescroll.js/mescroll.vue'
  import SearchBar from '../common/SearchBar'

  export default {
    name: 'Sellform',
    components: {SearchBar, MescrollVue},
    data () {
      return {
        wrapperHeight: 0,
        data: [],
        openid: localStorage.openid,
        postParams: {
          stat: '00'
        },
        mescroll: null, // mescroll实例对象
        mescrollDown: {},
        mescrollUp: { // 上拉加载的配置.
          callback: this.upCallback, // 上拉回调,此处简写; 相当于 callback: function(page, mescroll) { }
          page: {
            num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
            size: 5 //每页数据条数,默认10
          },
          htmlNodata: '<p class="upwarp-nodata">-- 我是有底线的 --</p>',
          noMoreSize: 1,
          empty: {
            warpId: "wrapper", //父布局的id (1.3.5版本支持传入dom元素)
            tip: "暂无相关数据~" //提示
          }
        },
        wrapperHeight: 0,
        saladmperms: false,
        backperms: false,
        edpriceperms: false,
        prodperms: false,
        puradmperms: false,
        purperms: false,
        saladmperms: false,
        salperms: false,
        sechperms: false,
        setlperms: false,
        stoadmperms: false,
        storperms: false,
        transperms: false,
        wladmperms: false,
        wlperms: false,
        userid: localStorage.userid,
        permissions: [],
        conditionSR: false,
        tabTitles: [],
        tabWidth: '25%',
      }
    },
    created() {
      //从首页进入刷新
      this.$parent.reload();
    },
    mounted() {
      //获取tab标签页title
      this.getLabels();

      this.wrapperHeight = document.documentElement.clientHeight - this.$refs.wrapper.getBoundingClientRect().top;
      this.userid = localStorage.userid;
      this.getPermission()
    },
    methods: {
      getLabels: function() {
        this.axios({
          method: 'get',
          params:{flowid:2},
          url: '/produce/Label!getLabels.action',
        }).then((response) => {
          if (response.data.msg == 'success') {
            this.$nextTick(() => {
              this.tabTitles = response.data.labels;
              this.tabWidth = (100 / response.data.labels.length) + '%';
            })
          } else {
            this.toastError("系统错误");
          }
        })
      },
      getPermission: function() {
        this.axios({
          method: 'get',
          params:{opttype:1},
          url: '/produce/OperatorPermission!getOperPerm.action?openid=' + localStorage.openid,
        }).then((response) => {
          if (response.data.msg == 'success') {
            this.$nextTick(() => {
              this.permissions = response.data.permission;
              console.log('permissions:', this.permissions)
            })
          } else {
            this.toastError("系统错误");
          }

        })
      },
      filterPerm: function(perm, roomid, departid, operatorid) {
        let status = false;
        if (perm == 0) {
          status = this.userid == operatorid;
        } else {
          let permissions = this.permissions;
          if (permissions.length == 0) return;
          for (let i=0; i<permissions.length; i++) {
            if (perm == permissions[i].permission) {
              if (permissions[i].permss.scopetype == 1) {
                if (permissions[i].srguid == roomid) {
                  status = true;
                } else {
                  status = status == true ? true :false;
                }
              } else if (permissions[i].permss.scopetype == 2) {
                if (permissions[i].departid == departid) {
                  status = true;
                } else {
                  status = status == true ? true :false;
                }
              } else if (permissions[i].permss.scopetype == 3) {
                if (permissions[i].srguid == roomid && permissions[i].departid == departid) {
                  status = true;
                } else {
                  status = status == true ? true :false;
                }
              } else if (permissions[i].permss.scopetype == 4) {
                status = true;
              } else {
                status = true;
              }
              //return status;

            }
          }

        }
        return status;
      },
      addItem: function() {
        this.$router.push({name: 'AddSellform'});
      },
      sellCheck: function(guid) {
        this.axios({
          method: 'post',
          url: '/sales/Sellform!sendAppro.action?openid=' + localStorage.openid,
          params: {guid: guid}
        }).then(response => {
          if(response.data.status == "true"){
            this.toastSuccess(response.data.result);
            this.getPageData('reset');
          }else if (response.data.status == "false"){
            this.toastError(response.data.result);
          } else {
            this.toastError('系统错误');
          }
        });
      },
      mescrollInit (mescroll) {
        this.mescroll = mescroll  // 如果this.mescroll对象没有使用到,则mescrollInit可以不用配置
      },
      upCallback (page, mescroll) {
        this.postParams.pageNo = page.num;
        this.postParams.pageSize = page.size;
        // 联网请求
        this.axios({
          method: 'get',
          url: '/sales/Sellform!list.action?openid=' + localStorage.openid,
          params: this.postParams
        }).then((response) => {
          if (response.data.status == 'true') {
            let res = response.data.result != undefined ? response.data.result : {list: {rows: []}};
            //设置财务数据查看权限
            if (res.list.pageNo == 1) {
              let permissions = res.permissions;
              this.saladmperms = permissions.saladmperms == 1 ? true : false;
              this.backperms = permissions.backperms == 1 ? true : false;
              this.edpriceperms = permissions.edpriceperms == 1 ? true : false;
              this.prodperms = permissions.prodperms == 1 ? true : false;
              this.puradmperms = permissions.puradmperms == 1 ? true : false;
              this.purperms = permissions.purperms == 1 ? true : false;
              this.saladmperms = permissions.saladmperms == 1 ? true : false;
              this.salperms = permissions.salperms == 1 ? true : false;
              this.sechperms = permissions.sechperms == 1 ? true : false;
              this.setlperms = permissions.setlperms == 1 ? true : false;
              this.stoadmperms = permissions.stoadmperms == 1 ? true : false;
              this.storperms = permissions.storperms == 1 ? true : false;
              this.transperms = permissions.transperms == 1 ? true : false;
              this.wladmperms = permissions.wladmperms == 1 ? true : false;
              this.wlperms = permissions.wlperms == 1 ? true : false;
              this.resetSetItem('saladmperms', permissions.saladmperms);
              this.resetSetItem('edpriceperms', permissions.edpriceperms);
              this.resetSetItem('setlperms', permissions.setlperms);
              this.resetSetItem('backperms', permissions.backperms);
              this.conditionSR = res.conditionSR;
            }
            // 如果是第一页需手动置空列表
            if (page.num === 1) this.data = []
            // 把请求到的数据添加到列表
            this.data = this.data.concat(res.list.rows);
            // 数据渲染成功后,隐藏下拉刷新的状态
            this.$nextTick(() => {
              mescroll.endSuccess(res.list.rows.length)
            })
            //将获取上一访问列表临时页码恢复正常
            if (this.mescrollUp.page.size > 5) {
              this.mescrollUp.page.num = this.$store.state.list.pageNo;
              this.mescrollUp.page.size = 5;
            }
          } else if (response.data.status == 'false') {
            this.toastError(response.data.result);
          } else {
            this.toastError("系统错误");
          }

        }).catch((e) => {
          // 联网失败的回调,隐藏下拉刷新和上拉加载的状态;
          mescroll.endErr()
        })
      },
      toOrderSure: function (guid, nodeid, status){
        let that = this;
        var promptconf = {
          title: '到货确认',
          text: '请输入到货确认信息!',
          type: "textArea",
          empty: true, // 是否允许为空
          onOK: function (input) {
            $.ajax({
              url: '/sales/Sellform!sendCar.action?openid=' + localStorage.openid,
              method: "POST",
              data: {"guid": guid,"description":input,"sellType":"orderSure", nodeid: nodeid, status:status},
              dataType: 'json',
              async : true,
              error:function(data){
                that.toastError('系统出现异常!');
              },
              success:function(data){
                if(data.info == 'ok'){
                  that.toastSuccess('操作成功!');
                }else{
                  that.toastError('操作失败!');
                }
                that.getPageData("reset");
              }
            });
          },
          onCancel: function () {
            //点击取消
          }
        }
        $.prompt(promptconf);
        $("#weui-prompt-input").remove(); //去除原始输入框
        $(".weui-dialog__bd").append('<textarea  rows="8" style="height:110px;" class="weui_input weui-prompt-input" id="weui-prompt-input" value=""></textarea>');
      },
      sellAssign:function (guid, nodeid, status){
        let that = this;
        var quitSRType = 1;
        var promptconf = {
          title: '出库派单',
          type: "textArea",
          empty: true, // 是否允许为空
          onOK: function (input) {
            $.ajax({
              url: '/sales/Sellform!sendCar.action?openid=' + localStorage.openid,
              method: "POST",
              data: {"guid": guid,"description":input,"sellType":"sellAssign", nodeid: nodeid, status:status},
              dataType: 'json',
              async : true,
              error:function(data){
                that.toastError('系统出现异常!');
              },
              success:function(data){
                if(data.info == 'ok'){
                  that.toastSuccess('操作成功!');
                }else{
                  that.toastError('操作失败!');
                }
                that.getPageData("reset");
              }
            });
          },
          onCancel: function () {
            //点击取消
          }
        }
        $.prompt(promptconf);
        $("#weui-prompt-input").remove(); //去除原始输入框
        $(".weui-dialog__bd").append('<textarea  rows="8" style="height:110px;" class="weui_input weui-prompt-input" id="weui-prompt-input" value=""></textarea>');
       // $(".weui-dialog__bd").append('<div   style=" position: relative;left: 81px;top: 2px; color: #999"><a href="javascript:void(0)"><label id="autoSwitch" style="color: #999;font-size:14px">从产成品库出库</label></a></div>');
        // $('#autoSwitch').click(function(){
        //    var typeText = $('#autoSwitch').text();
        //    if(typeText == '从产成品库出库'){
        //        $('#autoSwitch').text("从原材料库出库");
        //        quitSRType = 2;
        //    }else{
        //        $('#autoSwitch').text("从产成品库出库");
        //        quitSRType = 1;
        //    }
        // })
      },
      doAct: function (name, guid, nodeid, actname, annex) {
        let acts = this.$store.state.acts;

        if (name == 'qacheck') {
          this.toQaform(guid, nodeid, annex);
        } else if (name == 'delete') {
          this.delSellform(guid, nodeid, status);
        } else if (name == 'sendcar') {
          location.href = '/vuecode/#/sellform/sendCar?openid=' + this.openid + '&guid=' + guid + '&nodeid=' + nodeid + '&status=' + status;
        } else if (name == 'arrivalConfirm') {
          this.toOrderSure(guid, nodeid, status);
        } else {
          this.$router.push({name: acts[name], query: {guid:guid, status: this.postParams.stat, conditionSR: this.conditionSR, nodeid: nodeid, title: actname, annex: annex}});
        }
      },
      toQaform: function (guid, nodeid, annex) {
        window.location.href = '/trace/Qaform!index.action?openid='+localStorage.openid+'&orderguid='+guid+'&orderType=4'+'&nodeid='+nodeid+'&annex='+annex;
      },
      delSellform: function(guid, nodeid, status) {
        let that = this;
        var object = Object;
        $.confirm("确定要作废该订单？", function() {
          that.axios({
            method: 'post',
            url: '/sales/Sellform!zf.action?openid=' + localStorage.openid,
            params: {guid: guid, nodeid: nodeid, status: status}
          }).then((response) => {
            if (response.data.msg == 'ok') {
              that.$refs[guid][0].remove();
              that.toastSuccess('作废成功！');
            } else if (response.data.msg == 'not login') {
              that.toastError('请重新登录！');
            } else {
              that.toastError("系统错误");
            }
          })
        }, function() {
          //点击取消后的回调函数
        });
      },
      doSearch: function(keywords) {
        this.postParams.search = keywords;
        this.getPageData('reset');
      },
      viewItem: function (id) {
        this.$router.push({name: 'ViewSellform', query: {id: id}});
      },
      getPageData: function (type) {
        $('#wrapper').scrollTop(0);
        this.mescroll.resetUpScroll();
      },
      switchStatus: function (sta) {
        this.postParams.stat = sta;
        this.getPageData("reset");
      },
      delScrap: function (guid) {
        let that = this;
        var object = Object;
        $.confirm("确定删除?", function() {
          that.axios({
            method: 'post',
            url: '/sales/Sellform!zf.action?openid=' + localStorage.openid,
            params: {guid: guid}
          }).then((response) => {
            if (response.data.msg == 'ok') {
              // if (object.keys(that.$refs).length == 1) {
              //   $('#scrap').remove();
              // }
              that.$refs[guid][0].remove();
              that.toastSuccess('删除成功！');
            } else if (response.data.msg == 'not login') {
              that.toastError('请重新登录！');
            } else {
              that.toastError("系统错误");
            }
          })
        }, function() {
          //点击取消后的回调函数
        });
      },

    },
    activated () {
      //判断是否是返回上一页
      if (this.$store.state.list.reffer != this.$options.name) return;
      //获取上一次访问列表数据
      this.mescrollUp.page.num = 0;
      this.mescrollUp.page.size = this.$store.state.list.pageNo * this.mescrollUp.page.size;
      this.getPageData();
      //定位
      this.$nextTick(function(){
        let position = this.$store.state.list.postion //返回页面取出来
        $('#wrapper').scrollTop(position);
        let status = this.$store.state.list.status;
        this.postParams.status = status;
        if (status == 66 || status == 77) {
          $('.order-tabhd').scrollLeft(1500);
        }
      })
    },
    beforeRouteLeave(to, from, next){
      let position = $('#wrapper').scrollTop();
      let status = this.postParams.status;
      this.$store.commit('setPosition', position) //离开路由时把位置存起来
      this.$store.commit('setStatus', status)
      this.$store.commit('setPageNo', this.mescrollUp.page.num);
      this.$store.commit('setReffer', this.$options.name);
      next()
    }
  }



</script>

